Find the substrings within a string¶
for match in re.findall(p, S)
Find the substrings within a string.
Sample text :
‘Python exercises, PHP exercises, C# exercises’
Pattern :
‘exercises’
Note: There are two instances of exercises in the input string.
import re
S = 'Python exercises, PHP exercises, C# exercises'
pattern = 'exercises'
for match in re.findall(pattern, S):
print('Found "%s"' % match)
Output:
Found "exercises"
Found "exercises"
Found "exercises"